'use strict';

import assert from 'assert';
import controller from '../index.js';
import db from './creat_db.js';

// 淘宝 2.0 后端的 context 实例
const context = {
	"traceId": "0b83515215724167496355386d0682",
	"invokeId": "0b83515215724167496355386d0682",
	"miniappId": "3000000002059192",
	"data": {},
	"credentials": {
		"accessKeyId": "STS.NSRPr21rgQia4vRoz8wUybPya",
		"securityToken": "CAISgwJ1q6Ft5B2yfSjIr5DnG8iG3K1G5quKNlDji3pte9pVjZXSgzz2IHhEeXlvAOoetv8+mmxR6P0clqZdVplOWU3Da+B364xK7Q75pxcAPEXwv9I+k5SANTW5KXyShb3/AYjQSNfaZY3eCTTtnTNyxr3XbCirW0ffX7SClZ9gaKZ8PGD6F00kYu1bPQx/ssQXGGLMPPK2SH7Qj3HXEVBjt3gX6wo9y9zmmpTBsUWH3QSim7RJ/tSpGPX+MZkwZqUYesyuwel7epDG1CNt8BVQ/M909vccqWqX4YjHWwEKskvaarSPrMcSKRd6baU+H7RJpfT7k/lps+fYmp/s26jAvGbZzsW0GoABeQeG+WfAxY7tuubCvA7orSpljrrmFY3EUlohgSbRKqo4Ax+ycmjnXIbOPX5CHTJr1tcXSxlic21cVfZhJD49IKZ0LV0S2aIIQOzbksOXeLbZRxolWoxjeqFhILBVuljwKxiLIs/8Olw3fJ3NPOkyNBx3DSDVQngyAWh4Eo8Yje0=",
		"accessKeySecret": "3QGQwZfkp86TffRSG5PLyFTiGb2a1J5AwqVDtBp95TRm"
	},
	"openId": "AAE0BteyAJa2JQTHKbE7C3Hk",
	"mixNick": "t01hxDH58OJtKcLI0Oww8nUkcK8gR36q8bZsQoVKk3zHaw=",
	"accessToken": "",
	"env": "test",
	"sourceAppKey": "27846371",
	"fcName": "helloworld",
	"appOwnerOpenId": "AAG8BteyAJa2JQTHKbFMQM3K",
	"cloud": {
		"function": {
			"options": {
				"env": "test"
			}
		},
		"_options": {
			"traceId": "0b83515215724167496355386d0682",
			"handler": "main",
			"miniappId": "3000000002059192",
			"data": {},
			"openId": "AAE0BteyAJa2JQTHKbE7C3Hk",
			"__gatewayUrl": "http://gw-internal.m.mappcloud.com",
			"mixNick": "t01hxDH58OJtKcLI0Oww8nUkcK8gR36q8bZsQoVKk3zHaw=",
			"accessToken": "",
			"env": "test",
			"sourceAppKey": "27846371",
			"fcName": "helloworld",
			"appOwnerOpenId": "AAG8BteyAJa2JQTHKbFMQM3K",
			"requestId": "0b83515215724167496355386d0682",
			"cloudId": "aszglrnatu9t",
			"fcInvokeId": "0b83515215724167496355386d0682",
			"requestAppKey": "27846371",
			"appKey": "27858555",
			"rpcId": "9",
			"signSecret": "0a9deb8b5d3866d640f4e42185aaabcf",
			"sourceMiniAppId": "3000000002059192",
			"gatewayEnv": "online",
			"timestamp": 1572416749641
		},
		"db": {
			"config": {
				"env": "test"
			}
		}
	},
	"accountId": "1015371910934180",
	"requestId": "c751a259-87aa-4a28-ae1c-bd6d81c286f9",
	"service": {
		"logStore": "mps-fn-logstore",
		"versionId": "",
		"qualifier": "LATEST",
		"name": "s3ce16a69-416f-4019-a374-8ba097841172",
		"logProject": "jweutotg-1015371910934180"
	},
	"function": {
		"handler": "entry.handler",
		"initializationTimeout": 300,
		"memory": 256,
		"name": "fun-5db927001c9d447ed9da342d",
		"timeout": 10,
		"initializer": "entry.initializer"
	},
	"cloudId": "aszglrnatu9t",
	"fcInvokeId": "0b83515215724167496355386d0682",
	"requestAppKey": "27846371",
	"appKey": "27858555",
	"rpcId": "9",
	"region": "cn-zhangjiakou",
	"sourceMiniAppId": "3000000002059192"
};

describe('莫凡 controller 测试', () => {

	describe('main() 函数测试 返回 0', () => {

		it('main() 函数测试 return 0', async () => {
			let result = null;
			let test_db;
			try {
				// 输入库名称
				test_db = await db("wgtest");
				let obj = {
					openId: "mf-test001",
					data: {
						id: 1,
						name: 'dj'
					},
					cloud: {
						db: test_db.database //
					},
					NODE_LOCAL_ENV:true,
				};
				result = await controller.main(obj);
			} catch (e) {Ω
				result = e;
			}finally {
				try {
					await test_db.db.close();
				} catch (e) {

				}
			}

			console.log(result);
			assert.strictEqual(0, 0);
		});

	});
});
